package algri;

public class AnaLevelWarning {
	// 返回预警的图片
	public String what_level(String used, String netspeed) {
		String return_resultString = null;
		int used_Integer = 0;
		// 将used变量进行处理：字符串分割出数字部分并转换成int格式方便比较
		String[] str1 = used.split("G");
		for (int i = 0; i < str1.length; i++) {
			used_Integer = Integer.valueOf(str1[i]);
		}
		// 将netspeed变量进行格式化处理，字符串分割出数字部分转换为double格式
		// 1.查看倒数第四个字符是M还是k
		int net_str_length = netspeed.length();
		String net_levelString = netspeed.substring(net_str_length - 4, net_str_length - 3);
//		System.out.println(net_levelString);
		if (net_levelString.equals("k")) {
			// 如果是网速是k，直接转化为double
			String ready_turn = netspeed.substring(0, net_str_length - 4);
			Double netspeed_kbps = Double.valueOf(ready_turn);
			if (used_Integer > 1800 || netspeed_kbps < 20.0) {
				return_resultString = "level_two_warning.png";
			} else if (used_Integer < 1800
					&& ((netspeed_kbps > 20.0 || netspeed_kbps == 20.0) && netspeed_kbps < 100.0)) {
				return_resultString = "level_three_warning.png";
			} else if (used_Integer < 1800
					&& ((netspeed_kbps == 100.0 || netspeed_kbps > 100.0) && netspeed_kbps < 1024.0)) {
				return_resultString = "level_four_warning.png";
			}
		} else {
			// 如果是M，转化后与1M比较
			String ready_turn = netspeed.substring(0, net_str_length - 4);
			Double netspeed_Mbps = Double.valueOf(ready_turn);
//			System.out.println(netspeed_Mbps);
			if (netspeed_Mbps > 1.00) {
				return_resultString = "level_five_warning.png";
			}
			// 小于1M待定
		}
//		System.out.println(return_resultString);
		return return_resultString;
	}

	// 返回预警的等级
	public String return_Level(String used, String netspeed) {
		String return_resultString = null;
		int used_Integer = 0;
		// 将used变量进行处理：字符串分割出数字部分并转换成int格式方便比较
		String[] str1 = used.split("G");
		for (int i = 0; i < str1.length; i++) {
			used_Integer = Integer.valueOf(str1[i]);
		}
		// 将netspeed变量进行格式化处理，字符串分割出数字部分转换为double格式
		// 1.查看倒数第四个字符是M还是k
		int net_str_length = netspeed.length();
		String net_levelString = netspeed.substring(net_str_length - 4, net_str_length - 3);
//		System.out.println(net_levelString);
		if (net_levelString.equals("k")) {
			// 如果是网速是k，直接转化为double
			String ready_turn = netspeed.substring(0, net_str_length - 4);
			Double netspeed_kbps = Double.valueOf(ready_turn);
			if (used_Integer > 1800 || netspeed_kbps < 20.0) {
				return_resultString = "二级";
			} else if (used_Integer < 1800
					&& ((netspeed_kbps > 20.0 || netspeed_kbps == 20.0) && netspeed_kbps < 100.0)) {
				return_resultString = "三级";
			} else if (used_Integer < 1800
					&& ((netspeed_kbps == 100.0 || netspeed_kbps > 100.0) && netspeed_kbps < 1024.0)) {
				return_resultString = "四级";
			}
		} else {
			// 如果是M，转化后与1M比较
			String ready_turn = netspeed.substring(0, net_str_length - 4);
			Double netspeed_Mbps = Double.valueOf(ready_turn);
//			System.out.println(netspeed_Mbps);
			if (netspeed_Mbps > 1.00) {
				return_resultString = "五级";
			}
			// 小于1M待定
		}
		return return_resultString;
	}

	//仪表盘——硬盘容量
	public String ana_stoCapcity(String used,String total) {
		
		int used_Integer=0;
		int total_Integer=0;
		// 将used与total变量进行处理：字符串分割出数字部分并转换成int格式方便比较
		String[] str1 = used.split("G");
		for (int i = 0; i < str1.length; i++) {
		      used_Integer = Integer.valueOf(str1[i]);
		}
		// 将used变量进行处理：字符串分割出数字部分并转换成int格式方便比较
		String[] str2 = total.split("G");
		for (int i = 0; i < str2.length; i++) {
			total_Integer = Integer.valueOf(str2[i]);
		}
		double usedDou=Double.valueOf(used_Integer);
		double totalDou=Double.valueOf(total_Integer);
		double x=usedDou/totalDou;
		double stoCapcityDou=x*100;
		String reString=String.valueOf(stoCapcityDou);
		String resultString=reString.substring(0, reString.indexOf(".")).trim();
//		System.out.println("硬盘使用容量比率:"+resultString);
		return resultString;
	}
    //仪表盘——网速比率
    public String ana_netspeedCap(String netspeed) {
		String returnString=null;
		int net_str_length = netspeed.length();
		String net_levelString = netspeed.substring(net_str_length - 4, net_str_length - 3);
		if (net_levelString.equals("k")) {
			// 如果是网速是k，直接转化为double
			String ready_turn = netspeed.substring(0, net_str_length - 4);
			Double netspeed_kbps = Double.valueOf(ready_turn);
			double normDou=1024.00;
			double restDou=100*(netspeed_kbps/normDou);
			String restString=String.valueOf(restDou);
			returnString = restString.substring(0, restString.indexOf(".")).trim();
		} else {
			// 如果是M，转化后与1M比较
			String ready_turn = netspeed.substring(0, net_str_length - 4);
			Double netspeed_Mbps = Double.valueOf(ready_turn);
//			System.out.println(netspeed_Mbps);
			if (netspeed_Mbps > 1.00) {
				returnString="95";
			}
		}
//		System.out.println(returnString);
    	return returnString;
	}
}
